<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<view class="content wrap">
				<u-form>
					<u-form-item label="发货日期" label-width="170" left-icon="calendar"><u-input v-model="setMentiontime" placeholder="选择日期" type="select" @click="getT()"/></u-form-item>
				</u-form>
			</view>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="10">
							<view class="weikaishi3 yizuofei">
								<span><u-icon name="home" size="30" labelSize="15px" labelColor="#e84d74" label="收货方"></u-icon>：{{item.getUnit}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1">
								<span><u-button type="default" size="mini" @click="toguihua(item)">规划</u-button></span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="left">
							<view class="weikaishi6">
								<span><u-icon name="map" size="26" labelSize="13px" labelColor="#000000" label="地址"></u-icon>：{{item.getLocation}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" text-align="left">
							<view class="weikaishi4">
								<span><u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="备货区"></u-icon>：{{item.areanumber}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="weikaishi4 yiwancheng">
								<span><u-icon name="car" size="29" labelSize="14px" labelColor="#00c300" label="配送车辆" color="#00c300"></u-icon>：{{item.privatecarCarnumbers}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-collapse>
						<u-collapse-item :title="'待拣单数：'+item.daijiannum+'，已合：'+item.yihenum">
							<u-row v-for="(item1,index1) in item.list" :key="index1">
								<u-col span="12" text-align="left" v-if="item1.outOrderStatus == '未完成'">
									<view class="u-m-t-2 weikaishi3 lanse" @click="weihedanmingxi(item1.storageOutNumber)">
										<span><u-icon name="order" size="29" labelSize="14px" labelColor="#2b85e4" label="单号" color="#2b85e4"></u-icon>：{{item1.storageOutNumber}}</span>
									</view>
								</u-col>
								<u-col span="12" text-align="left" v-if="item1.outOrderStatus == '待审核'">
									<view class="u-m-t-2 weikaishi3 yiwancheng" @click="weihedanmingxi(item1.storageOutNumber)">
										<span><u-icon name="order" size="29" labelSize="14px" labelColor="#00c300" label="单号" color="#00c300"></u-icon>：{{item1.storageOutNumber}}</span>
									</view>
								</u-col>
								<u-col span="12" text-align="left">
									<view class=" u-m-t-2 weikaishi3">
										<span><u-icon name="calendar" size="29" labelSize="14px" labelColor="#000000" label="制单日期" color="#000000"></u-icon>：{{item1.setMentiontime}}</span>
									</view>
								</u-col>
								<u-col span="12" text-align="left">
									<view class=" u-m-t-2 weikaishi3">
										<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="应拣数" color="#000000"></u-icon>：{{item1.storageNumber}}/{{item1.yingvolume}}m3</span>
									</view>
								</u-col>
								<u-col span="12" text-align="left" v-if="item1.storageNumber != item1.printnum">
									<view class=" u-m-t-2 weikaishi3">
										<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#000000" label="已拣数" color="#000000"></u-icon>：{{item1.printnum}}</span>
									</view>
								</u-col>
								<u-col span="12" text-align="left" v-else>
									<view class="u-m-t-2 weikaishi3 yiwancheng">
										<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300" label="已拣数" color="#00c300"></u-icon>：{{item1.printnum}}</span>
									</view>
								</u-col>
								<u-col span="12" text-align="right">
									<view class="u-m-t-10 u-line-1">
										<span><u-button type="default" size="default" @click="totask(item1)">拣货列表</u-button></span>
									</view>
								</u-col>
								<u-col span="12" text-align="right" >
									<view class="u-m-t-25 u-line-1">
									</view>
								</u-col>
							</u-row>
							<view v-for="(item2,index2) in item.list2" :key="index2">
								<u-row>
									<u-col span="12" text-align="left" v-if="item2.outOrderStatus == '未完成'">
										<view class="u-m-t-2 weikaishi3 lanse">
											<span @click="yihedanmingxi(item2)"><u-icon name="order" size="29" labelSize="14px" labelColor="#2b85e4" label="单号" color="#2b85e4"></u-icon>：{{item2.storageOutNumber}}</span>
										</view>
									</u-col>
									<u-col span="12" text-align="left"  v-if="item2.outOrderStatus == '待审核'">
										<view class="u-m-t-2 weikaishi3 yiwancheng">
											<span @click="yihedanmingxi(item2)"><u-icon name="order" size="29" labelSize="14px" labelColor="#00c300" label="单号" color="#00c300"></u-icon>：{{item2.storageOutNumber}}</span>
										</view>
									</u-col>
									<u-col span="12" text-align="left">
										<view class=" u-m-t-2 weikaishi3">
											<span><u-icon name="calendar" size="29" labelSize="14px" labelColor="#000000" label="制单日期" color="#000000"></u-icon>：{{item2.setMentiontime}}</span>
										</view>
									</u-col>
									<u-col span="12" text-align="left">
										<view class=" u-m-t-2 weikaishi3">
										<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="应拣数" color="#000000"></u-icon>：{{item2.storageNumber}}/{{item2.yingvolume}}m3</span>
										</view>
									</u-col>
									<u-col span="12" text-align="left" v-if="item2.storageNumber != item2.printnum">
										<view class=" u-m-t-2 weikaishi3">
											<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#000000" label="已拣数" color="#000000"></u-icon>：{{item2.printnum}}</span>
										</view>
									</u-col>
									<u-col span="12" text-align="left" v-else>
										<view class="u-m-t-2 weikaishi3 yiwancheng">
											<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300" label="已拣数" color="#00c300"></u-icon>：{{item2.printnum}}</span>
										</view>
									</u-col>
									<u-col span="12" text-align="right">
										<view class="u-m-t-2 u-line-1">
											<span><u-button type="default" size="default" @click="totaskss(item2)">拣货列表</u-button></span>
										</view>
									</u-col>
									<u-col span="12" text-align="right" >
										<view class="u-m-t-25 u-line-1">
										</view>
									</u-col>
								</u-row>
							</view>
						</u-collapse-item>
					</u-collapse>
				</view>
			</view>
		</u-card>
		<view>
			<u-calendar v-model="show" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
		</view>
		<u-popup v-model="popupShow" mode="center" closeable width="660rpx" height="720rpx" border-radius="10">
			<view class="u-text-center u-m-t-20 weikaishi3"><u-icon name="order" size="30" labelSize="15px" labelColor="#000000" label="拣货明细"></u-icon></view>
			<u-card padding="16" v-for="(item,index) in dataList2" :key="index">
				<view class="" slot="head">
					<view class="wrap">
						<u-row>
							<u-col span="12">
								<view class="weikaishi3 lanse">
									<span>{{item.storageGoodsname}},{{item.goodsNo}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="" slot="body">
					<view class="wrap">
						<u-row>
							<u-col span="5" text-align="center">
								<view class="weikaishi4 u-line-1 u-m-t-10">
									<span>批次</span>
								</view>
							</u-col>
							<u-col span="3" text-align="center">
								<view class="weikaishi4 u-line-1 u-m-t-10">
									<span>应拣</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="weikaishi4 u-line-1 u-m-t-10">
									<span>实拣</span>
								</view>
							</u-col>
						</u-row>
						<u-row v-for="(item1,index1) in item.list" :key="item1.id">
							<u-col span="5" text-align="center">
								<view class=" u-m-t-10 weikaishi4 huanghang">
									<span>{{item1.storageBatchnumber}}</span>
								</view>
							</u-col>
							<u-col span="3" text-align="center" v-if="item1.storageNumber == item1.realNum">
								<view class=" u-m-t-10 weikaishi4 yiwancheng">
									<span>{{item1.storageNumber}}</span>
								</view>
							</u-col>
							<u-col span="3" text-align="center" v-else>
								<view class=" u-m-t-10 weikaishi4">
									<span>{{item1.storageNumber}}</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center" v-if="item1.storageNumber == item1.realNum">
								<view class=" u-m-t-10 weikaishi4 yiwancheng">
									<span>{{item1.realNum}}</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center" v-else>
								<view class=" u-m-t-10 weikaishi4">
									<span>{{item1.realNum}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</u-card>
		</u-popup>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				setMentiontime:'',
				dataList: [],
				dataList2: [],
				show:false,
				popupShow:false,
				areanumberlist:[],
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
		},
		onShow() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			toguihua(item){
				this.$Router.push({ 
					name: 'storage_out_plan',
					params: { 
						getUnitId:item.getUnitId,
						getLocationId:item.getLocationId,
						setMentiontime:this.setMentiontime
					},
				})
			},
			yihedanmingxi(item){
				let storageOutNumbers = []
				for(let item1 of this.dataList) {
					if(item.getUnitId == item1.getUnitId && item.getLocationId == item1.getLocationId){
						for(let item2 of item1.list2) {
							if(item2.id == item.id){
								for(let item3 of item2.list2) {
									storageOutNumbers.push(item3.storageOutNumber)
								}
							}
						}
					}
				}
				this.$http.post('/rest/storageOut/apporderdetailslist?storageOutNumbers='+storageOutNumbers,{
				},{
					params: {
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList2 = res.data.data
					this.popupShow = true
				})
			},
			weihedanmingxi(storageOutNumber){
				let storageOutNumbers = []
				storageOutNumbers.push(storageOutNumber)
				this.$http.post('/rest/storageOut/apporderdetailslist?storageOutNumbers='+storageOutNumbers,{
				},{
					params: {
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList2 = res.data.data
					this.popupShow = true
				})
			},
			checkboxChange(e){
				console.log(e)
			},
			totaskss(item){
				let storageOutNumbers = []
				let privatecarCarnumbers = ''
				let areanumber = ''
				let getUnit = ''
				let getLocation = ''
				for(let item1 of this.dataList) {
					if(item.getUnitId == item1.getUnitId && item.getLocationId == item1.getLocationId){
						privatecarCarnumbers = item1.privatecarCarnumbers
						areanumber = item1.areanumber
						getUnit = item1.getUnit
						getLocation = item1.getLocation
						for(let item2 of item1.list2) {
							if(item2.id == item.id){
								for(let item3 of item2.list2) {
									storageOutNumbers.push(item3.storageOutNumber)
								}
							}
						}
					}
				}
				let storage_out_task = {}
				storage_out_task.storageOutNumber = storageOutNumbers
				storage_out_task.privatecarCarnumbers = privatecarCarnumbers
				storage_out_task.areanumber = areanumber
				storage_out_task.getUnit = getUnit
				storage_out_task.getLocation = getLocation
				uni.setStorageSync('storage_out_task', storage_out_task);
				this.$Router.push({ 
					name: 'storage_out_task_mark'
				})
			},
			totask(item){
				let storageOutNumbers = []
				let privatecarCarnumbers = ''
				let areanumber = ''
				let getUnit = ''
				let getLocation = ''
				storageOutNumbers.push(item.storageOutNumber)
				for(let item1 of this.dataList) {
					if(item.getUnitId == item1.getUnitId && item.getLocationId == item1.getLocationId){
						privatecarCarnumbers = item1.privatecarCarnumbers
						areanumber = item1.areanumber
						getUnit = item1.getUnit
						getLocation = item1.getLocation
					}
				}
				let storage_out_task = {}
				storage_out_task.storageOutNumber = storageOutNumbers
				storage_out_task.privatecarCarnumbers = privatecarCarnumbers
				storage_out_task.areanumber = areanumber
				storage_out_task.getUnit = getUnit
				storage_out_task.getLocation = getLocation
				uni.setStorageSync('storage_out_task', storage_out_task);
				this.$Router.push({ 
					name: 'storage_out_task'
				})
			},
			change(e) {
				this.setMentiontime = e.result
				this.refresh()
			},
			getT(){
				this.show = true
			},
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/storageOut/appoutstockworklist2',{
				},{
					params: {
						setMentiontime: this.setMentiontime
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
					uni.hideLoading()
				})
				
			},
		},
	}
</script>
<style lang="scss">
	.huanhang{
		word-break:break-all;
	}
</style>